/********************************************************************************
*																				*
*  Las Venturas Playground - Commands/playerCommands.nut						*
*																				*
*  This file will hold all player commands.										*
*																				*
********************************************************************************/

local cmdHandler = CommandHandler ();

// Command: /help
// Params: void
// Author: Matthias
local function cmdHelp (playerid, cmdWords, cmdStr)
{
	sendPlayerMessage(playerid, "* Check /commands for a command list.", 0xFF9900FF, true);
	sendPlayerMessage(playerid, "* Please read /rules and /credits.", 0xFFFFFF00, true);
}
cmdHandler.registerCommand ("/help", Command (cmdHelp));


// Command: /commands
// Params: void
// Author: Sander
// Note by Pugwipe: would be nice to make this dynamic - TODO
local function cmdCommands (playerid, cmdWords, cmdStr)
{
	sendPlayerMessage(playerid, "The following commands are available:", 0xFF9900FF, true);
	sendPlayerMessage(playerid, "/carteleport, /help, /kill, /vehicle, /parking, /teleport, /vehicles, /vr, /weapon, /weapons", 0xFFFFFF00, true);
}
cmdHandler.registerCommand ("/commands", Command (cmdCommands));

// Command: /ctp or /carteleport
// Params: (int) player
// Author: Sander
local function cmdCarTeleport (playerid, cmdWords, cmdStr)
{
    if (cmdWords.len () < 2) 
    {
        sendPlayerMessage(playerid, "[FF0000FF]* Usage: [FFFF0000]/ctp [PlayerID]", 0xFFFFFFFF, true);
        return;
    }
    
    if (!isPlayerInAnyVehicle (playerid))
    {
        sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ Forgot your vehicle?", 0xFFFFFFFF, true);
        return;
    }
    
    local targetPlayer = getPlayerFromInput (cmdWords[1]);
    if (targetPlayer < 0) {
        sendInvalidPlayerMessage (playerid, targetPlayer);
        return;
    }
    
    local fVehPos = getPlayerCoordinates (targetPlayer);
	setVehicleCoordinates(getPlayerVehicleId (playerid), fVehPos[0], fVehPos[1], fVehPos[2] + 2.0);
    sendPlayerMessage (playerid, "*** You have been car-teleported to " + getPlayerName(targetPlayer) + "!", 0xFFFFFFFF, true);
}
cmdHandler.registerCommand ("/ctp", Command (cmdCarTeleport));
cmdHandler.registerCommand ("/carteleport", Command (cmdCarTeleport));

// Command: /vr
// Params: void
// Author: Sander
local function cmdVr (playerid, cmdWords, cmdStr)
{
    if (isPlayerOnFoot (playerid)) 
	{
		sendPlayerMessage(playerid, "[FF0000FF]/[FFFF0000]![FF0000FF]\\ Forgot your vehicle?", 0xFFFFFFFF, true);
		return;
	}
    
    setVehicleEngineHealth(getPlayerVehicleId(playerid), 1000);
	sendPlayerMessage(playerid, "*** Your vehicle has been repaired.", 0xFFFFFFFF);
}
cmdHandler.registerCommand ("/vr", Command (cmdVr));

// Command: /kill
// Params: void
// Author: Sander
local function cmdKill (playerid, cmdWords, cmdStr)
{
    setPlayerHealth (playerid, -1);
}
cmdHandler.registerCommand ("/kill", Command (cmdKill));

// Command: /kill
// Params: player (name or id)
// Author: Sander
local function cmdTeleport (playerid, cmdWords, cmdStr)
{
    if (cmdWords.len () < 2) 
    {
        sendPlayerMessage (playerid, "[FF0000FF]* Usage: [FFFF0000]/tp [PlayerID]", 0xFFFFFFFF, true);
        return;
    }
    
    local targetPlayer = getPlayerFromInput (cmdWords[1]);
    if (targetPlayer < 0) {
        sendInvalidPlayerMessage (playerid, targetPlayer);
        return;
    }
    
    local aPlayerPos = getPlayerCoordinates (targetPlayer);
    setPlayerCoordinates (playerid, aPlayerPos[0], aPlayerPos[1], aPlayerPos[2]);
	sendPlayerMessage (playerid, "[FFFFFF00]*** You have been teleported to " + getPlayerName (targetPlayer) + ".", 0xFFFFFFFF, true);
	setCameraBehindPlayer (playerid);
}
cmdHandler.registerCommand ("/tp", Command (cmdTeleport));
cmdHandler.registerCommand ("/teleport", Command (cmdTeleport));

// Command: /v or /vehicle
// Params: (int) vehicle
// Author: Sander
local function cmdVehicle (playerid, cmdWords, cmdStr)
{
    if (cmdWords.len () < 2 || !isNumeric (cmdWords[1])) 
    {
		sendPlayerMessage(playerid, "[FF0000FF]* Usage: [FFFF0000]/v [VehicleID] [FF0000FF]See /vehicles for common models.", 0xFFFFFFFF, true);
        return;
    }
    
    local model = cmdWords[1].tointeger ();
    
    // Is the vehicle valid?
	if(model < 0 || model == 41 || model == 107 || model == 111 || model > 123)
	{
		sendPlayerMessage (playerid, "* Invalid model id!", 0xFFFFFFFF, true );
		return;
	}
    
    local pos;
    if (isPlayerInAnyVehicle (playerid)) pos = getVehicleCoordinates (getPlayerVehicleId (playerid));
	else pos = getPlayerCoordinates (playerid);
    
    local heading = getPlayerHeading (playerid);
	local vehicle = createVehicle (model, pos[0], pos[1], pos[2], heading, 1, 1, 1, 1);
    
    if (vehicle == INVALID_VEHICLE_ID) 
    {
		sendPlayerMessage (playerid, "*** Unable to create a " + getVehicleName(model) + "." );
        return;
    }
    
    warpPlayerIntoVehicle (playerid, vehicle);
    sendPlayerMessage (playerid, "*** " + getVehicleName(model) + " spawned at your position (ID " + vehicle + ")." );
}
cmdHandler.registerCommand ("/v", Command (cmdVehicle));
cmdHandler.registerCommand ("/vehicle", Command (cmdVehicle));

	
// Command: /vehicles
// Params: void
// Author: Sander
function cmdVehicles (playerid, cmdWords, cmdStr)
{
	sendPlayerMessage(playerid, "[FF990000]Frequently used vehicle models", 0xFFFFFFFF, true);
	sendPlayerMessage(playerid, "[FFFFFF00]3 Banshee - 18 Coquette - 40 Infernus - 62 PMP600 - 90 Sultan RS", 0xFFFFFFFF, true);
	sendPlayerMessage(playerid, "[FFFFFF00]91 SuperGT - 108 NRG900 - 112 Annihilator", 0xFFFFFFFF, true);
}
cmdHandler.registerCommand ("/vehicles", Command (cmdVehicles));

// Command: /w or /weapon
// Params: (int) weapon
// Author: Sander
function cmdWeapon (playerid, cmdWords, cmdStr)
{
    if (cmd.len() < 2 || !isNumeric (cmdWords[1])) {
        sendPlayerMessage (playerid, "[FF0000FF]Usage: [FFFF0000]/w [WeaponID] [FF0000FF]See /weapons for weapon ID's", 0xFFFFFFFF, true);
        return;
    }
    
    local weaponID = cmdWords[1].tointeger ();
    givePlayerWeapon (playerid, weaponID, 999);
}
cmdHandler.registerCommand ("/w", Command (cmdWeapon));
cmdHandler.registerCommand ("/weapon", Command (cmdWeapon));

function cmdWeapons (playerid, cmdWords, cmdStr)
{
	sendPlayerMessage(playerid, "[FF990000]Frequently used weaons", 0xFFFFFFFF, true);
	sendPlayerMessage(playerid, "[FFFFFF00]4 Grenade - 5 Molotov - 9 Desert Eagle", 0xFFFFFFFF, true);
	sendPlayerMessage(playerid, "[FFFFFF00]12 Micro UZI - 14 AK47 - 18 Rocket Launcher", 0xFFFFFFFF, true);
}
cmdHandler.registerCommand ("/weapons", Command (cmdWeapons));
